package com.varton.handler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@MappedJdbcTypes({JdbcType.VARCHAR,JdbcType.CHAR})
public class StringHandler extends BaseTypeHandler<String>{
    public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
        System.out.println("custom type handler");
        ps.setString(i,parameter);
    }

    public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
        System.out.println("custom type handler");
        return rs.getString(columnName);
    }

    public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        System.out.println("custom type handler");
        return rs.getString(columnIndex);
    }

    public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        System.out.println("custom type handler ");
        return cs.getString(columnIndex);
    }
}
